async function toggleAccordionAndSelect(element){
    var content = element.nextElementSibling;
    if (content.style.display !== 'block') {
        // 展开内容
        content.style.display = 'block';

        // 请求并展示数据
        console.log("这里请调用请求函数获取到selectData");
        const selectData = await requestSelect();
        console.log(selectData);
        const cards = selectData.cards;
        displaySelectData(cards);
    } else {
        // 如果内容已经是展开状态，直接关闭，不做请求
        content.style.display = 'none';
    }
}
function displaySelectData(cards) {
    const table = document.getElementById('selectTable');
    const tbody = table.querySelector('tbody');
    tbody.innerHTML = '';
    cards.forEach(row => {
        const cardInfo=row.card_list
        console.log(row,"row")
        // 创建一个表格行
        const tr = document.createElement('tr');

        const td = document.createElement('td');
        td.textContent = cardInfo.CardId;
        tr.appendChild(td);

        const td1 = document.createElement('td');
        td1.textContent = cardInfo.CardName;
        tr.appendChild(td1);

        const td2 = document.createElement('td');
        td2.textContent = cardInfo.CardIntroduction;
        tr.appendChild(td2);

        const td3 = document.createElement('td');

        // 对信息进行拼接和可视化展示
        function appendDescription(content, condition, description) {
            if (condition) {
                content += description + "，";
            }
            return content;
        }
        function appendCourses(content, condition, description, courses) {
            if (condition) {
                content += description;
                const courseNames = courses.map(course => course.courseName+"  其id 为"+course.courseID,"的课程").join(", ");
                content += courseNames + "，";
            }
            return content;
        }
        var content = "";
        content = appendDescription(content, cardInfo.IsLimitDays, "这个卡限制时间");
        content = appendDescription(content, cardInfo.IsLimitTimes, "这个卡限制次数");
        content = appendDescription(content, cardInfo.IsSupportGroup, "支持团课");
        content = appendDescription(content, cardInfo.IsSupportTeam, "支持小班课");
        content = appendDescription(content, cardInfo.IsSupportVip, "支持私教课");

        content = appendCourses(content, cardInfo.IsSupportSpecial, "对以下课程有特殊的支持: ", row.support_course_info);
        content = appendCourses(content, cardInfo.IsForbidSpecial, "对以下课程有特殊的禁止: ", row.forbid_course_info);

        if (content!==""){
            // 有时候真的可能一个信息都没有，特别是测试的时候
            content = content.trim().replace(/，$/, "") + "。";
        }
        td3.textContent = content;
        tr.appendChild(td3);
        tbody.appendChild(tr);
    });
}
async function requestSelect(){
    const url=`${config.server}`+"/api/select/all/card"
    const data={
    }
    const response=await fetch(url,{
        method:"POST",
        headers: { 'Content-Type': 'application/json' },
        body:JSON.stringify(data)
    })
    const getdata=await response.json()
    if(response.ok){
        return getdata
    }else{
        console.log("获取数据失败",getdata)
    }
}